<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.2/css/all.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"littlefxc.github.io","root":"/blog/","images":"/blog/images","scheme":"Mist","version":"8.2.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/blog/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}};
  </script>
<meta property="og:type" content="website">
<meta property="og:title" content="一年春又来">
<meta property="og:url" content="http://littlefxc.github.io/page/19/index.html">
<meta property="og:site_name" content="一年春又来">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="一年春又来">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="http://littlefxc.github.io/page/19/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : true,
    isPost : false,
    lang   : 'zh-CN'
  };
</script>
<title>一年春又来</title>
  




  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

<link rel="alternate" href="/blog/atom.xml" title="一年春又来" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/blog/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">一年春又来</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/blog/" rel="section"><i class="home                          //首页 fa-fw"></i>首页</a></li>
        <li class="menu-item menu-item-archives"><a href="/blog/archives/" rel="section"><i class="archive          //归档 fa-fw"></i>归档</a></li>
        <li class="menu-item menu-item-categories"><a href="/blog/categories/" rel="section"><i class="th           //分类 fa-fw"></i>分类</a></li>
        <li class="menu-item menu-item-tags"><a href="/blog/tags/" rel="section"><i class="tags                     //标签 fa-fw"></i>标签</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-overview-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">一年春又来</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">184</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/blog/categories/">
          
        <span class="site-state-item-count">35</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/blog/tags/">
          
        <span class="site-state-item-count">115</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner index posts-expand">

    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2019/05/06/window%E5%8F%B3%E9%94%AE%E8%8E%B7%E5%8F%96%E7%AE%A1%E7%90%86%E5%91%98%E6%9D%83%E9%99%90/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/blog/2019/05/06/window%E5%8F%B3%E9%94%AE%E8%8E%B7%E5%8F%96%E7%AE%A1%E7%90%86%E5%91%98%E6%9D%83%E9%99%90/" class="post-title-link" itemprop="url">window右键获取管理员权限</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2019-05-06 19:00:54" itemprop="dateCreated datePublished" datetime="2019-05-06T19:00:54+08:00">2019-05-06</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-03-25 21:15:49" itemprop="dateModified" datetime="2021-03-25T21:15:49+08:00">2021-03-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/blog/categories/Windows/" itemprop="url" rel="index"><span itemprop="name">Windows</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="文件名：获取管理员的所有权限–带图标-reg"><a href="#文件名：获取管理员的所有权限–带图标-reg" class="headerlink" title="文件名：获取管理员的所有权限–带图标.reg"></a>文件名：获取管理员的所有权限–带图标.reg</h2><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">Windows Registry Editor Version <span class="number">5</span>.<span class="number">00</span></span><br><span class="line">[HKEY_CLASSES_ROOT\*\shell\runas]</span><br><span class="line">[HKEY_CLASSES_ROOT\*\shell\runas]</span><br><span class="line">@=&quot;获取超级管理员的所有权限&quot;</span><br><span class="line">&quot;Icon&quot;=&quot;C:\\Windows\\System32\\imageres.dll,-<span class="number">78</span>&quot;</span><br><span class="line">&quot;NoWorkingDirectory&quot;=&quot;&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\*\shell\runas\command]</span><br><span class="line">@=&quot;<span class="built_in">cmd</span>.exe /c takeown /f \&quot;%<span class="number">1</span>\&quot; &amp;&amp; icacls \&quot;%<span class="number">1</span>\&quot; /grant administrators:F&quot;</span><br><span class="line">&quot;IsolatedCommand&quot;=&quot;<span class="built_in">cmd</span>.exe /c takeown /f \&quot;%<span class="number">1</span>\&quot; &amp;&amp; icacls \&quot;%<span class="number">1</span>\&quot; /grant administrators:F&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\Directory\shell\runas]</span><br><span class="line">[HKEY_CLASSES_ROOT\Directory\shell\runas]</span><br><span class="line">@=&quot;获取超级管理员的所有权限&quot;</span><br><span class="line">&quot;Icon&quot;=&quot;C:\\Windows\\System32\\imageres.dll,-<span class="number">78</span>&quot;</span><br><span class="line">&quot;NoWorkingDirectory&quot;=&quot;&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\Directory\shell\runas\command]</span><br><span class="line">@=&quot;<span class="built_in">cmd</span>.exe /c takeown /f \&quot;%<span class="number">1</span>\&quot; /r /d y &amp;&amp; icacls \&quot;%<span class="number">1</span>\&quot; /grant administrators:F /t&quot;</span><br><span class="line">&quot;IsolatedCommand&quot;=&quot;<span class="built_in">cmd</span>.exe /c takeown /f \&quot;%<span class="number">1</span>\&quot; /r /d y &amp;&amp; icacls \&quot;%<span class="number">1</span>\&quot; /grant administrators:F /t&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\dllfile\shell]</span><br><span class="line">[HKEY_CLASSES_ROOT\dllfile\shell\runas]</span><br><span class="line">@=&quot;获取超级管理员的所有权限&quot;</span><br><span class="line">&quot;HasLUAShield&quot;=&quot;&quot;</span><br><span class="line">&quot;NoWorkingDirectory&quot;=&quot;&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\dllfile\shell\runas\command]</span><br><span class="line">@=&quot;<span class="built_in">cmd</span>.exe /c takeown /f \&quot;%<span class="number">1</span>\&quot; &amp;&amp; icacls \&quot;%<span class="number">1</span>\&quot; /grant administrators:F&quot;</span><br><span class="line">&quot;IsolatedCommand&quot;=&quot;<span class="built_in">cmd</span>.exe /c takeown /f \&quot;%<span class="number">1</span>\&quot; &amp;&amp; icacls \&quot;%<span class="number">1</span>\&quot; /grant administrators:F&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\Drive\shell\runas]</span><br><span class="line">[HKEY_CLASSES_ROOT\Drive\shell\runas]</span><br><span class="line">@=&quot;获取超级管理员的所有权限&quot;</span><br><span class="line">&quot;Icon&quot;=&quot;C:\\Windows\\System32\\imageres.dll,-<span class="number">78</span>&quot;</span><br><span class="line">&quot;NoWorkingDirectory&quot;=&quot;&quot;</span><br><span class="line">[HKEY_CLASSES_ROOT\Drive\shell\runas\command]</span><br><span class="line">@=&quot;<span class="built_in">cmd</span>.exe /c takeown /f \&quot;%<span class="number">1</span>\&quot; /r /d y &amp;&amp; icacls \&quot;%<span class="number">1</span>\&quot; /grant administrators:F /t&quot;</span><br><span class="line">&quot;IsolatedCommand&quot;=&quot;<span class="built_in">cmd</span>.exe /c takeown /f \&quot;%<span class="number">1</span>\&quot; /r /d y &amp;&amp; icacls \&quot;%<span class="number">1</span>\&quot; /grant administrators:F /t&quot;</span><br></pre></td></tr></table></figure>
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2019/05/06/spring-boot-starter-validation%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/blog/2019/05/06/spring-boot-starter-validation%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" class="post-title-link" itemprop="url">spring-boot-starter-validation学习笔记</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2019-05-06 18:55:03" itemprop="dateCreated datePublished" datetime="2019-05-06T18:55:03+08:00">2019-05-06</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-03-25 21:15:49" itemprop="dateModified" datetime="2021-03-25T21:15:49+08:00">2021-03-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/blog/categories/Java/" itemprop="url" rel="index"><span itemprop="name">Java</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p>开发过程中，后台的参数校验是必不可少的，本文关于 <code>spring-boot-starter-validation</code>的学习笔记。</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/blog/2019/05/06/spring-boot-starter-validation%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2019/05/05/%E8%A7%84%E5%88%99%E5%BC%95%E6%93%8EDrools%E6%A8%A1%E6%9D%BF%E7%BC%96%E8%AF%91/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/blog/2019/05/05/%E8%A7%84%E5%88%99%E5%BC%95%E6%93%8EDrools%E6%A8%A1%E6%9D%BF%E7%BC%96%E8%AF%91/" class="post-title-link" itemprop="url">规则引擎Drools模板编译</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2019-05-05 20:14:08" itemprop="dateCreated datePublished" datetime="2019-05-05T20:14:08+08:00">2019-05-05</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-03-25 21:15:49" itemprop="dateModified" datetime="2021-03-25T21:15:49+08:00">2021-03-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/blog/categories/Java/" itemprop="url" rel="index"><span itemprop="name">Java</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <h2 id="规则引擎-Drools-模板编译"><a href="#规则引擎-Drools-模板编译" class="headerlink" title="规则引擎 Drools 模板编译"></a>规则引擎 Drools 模板编译</h2><h2 id="1-模板编译"><a href="#1-模板编译" class="headerlink" title="1.模板编译"></a>1.模板编译</h2><h3 id="1-1依赖"><a href="#1-1依赖" class="headerlink" title="1.1依赖"></a>1.1依赖</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.drools<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>drools-templates<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>7.7.0.Final<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="1-2建立模板"><a href="#1-2建立模板" class="headerlink" title="1.2建立模板"></a>1.2建立模板</h3><p>新建模板文件 test.drt</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">template header</span><br><span class="line">condition</span><br><span class="line">execution</span><br><span class="line"></span><br><span class="line"><span class="keyword">package</span> template</span><br><span class="line"></span><br><span class="line">template <span class="string">&quot;this is a test&quot;</span></span><br><span class="line"></span><br><span class="line">    rule <span class="string">&quot;test_@&#123;row.rowNumber&#125;&quot;</span></span><br><span class="line">        when</span><br><span class="line">            @&#123;condition&#125;</span><br><span class="line">        then</span><br><span class="line">            System.out.println(@&#123;execution&#125;);</span><br><span class="line">    end</span><br><span class="line"></span><br><span class="line">end template</span><br></pre></td></tr></table></figure>

<p>说明<br>规则模板主要由两部分构成：</p>
<p>Template header 定义了在模板中使用的变量。<br>模板中以 “template name” 开头, 以”end template” 结尾, 中间定义了模板的内容。变量占位符使用 @{variable_name} .<br>@{row.rowNumber}是一个特殊的变量, 每次会按顺序生成一个行号, 可用于区分规则名。</p>
<h2 id="1-3-渲染模板生成规则文件"><a href="#1-3-渲染模板生成规则文件" class="headerlink" title="1.3 渲染模板生成规则文件"></a>1.3 渲染模板生成规则文件</h2><p>渲染模板的流程，先将数据封装为 DataProvider，然后通过 DataProviderCompiler 使用 DataProvider 将模板编译为 DRL。</p>
<p>Drools支持数组类型的DataProvider, ArrayDataProvider实现了DataProvider,  示例</p>
 <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">InputStream templateStream = DataDrivenTemplateExample.class.getResourceAsStream(<span class="string">&quot;/rules/SimpleTemplateExample.drt&quot;</span>);</span><br><span class="line"><span class="comment">// @&#123;row.rowNumber&#125;=数组下标, @&#123;condition&#125;=规则条件, @&#123;execution&#125;=规则动作</span></span><br><span class="line">DataProvider data = <span class="keyword">new</span> ArrayDataProvider(<span class="keyword">new</span> String[][]&#123;</span><br><span class="line">    <span class="keyword">new</span> String[]&#123;<span class="string">&quot;String(this == \&quot;规则条件\&quot;)&quot;</span>, <span class="string">&quot;\&quot;规则动作\&quot;&quot;</span>&#125;</span><br><span class="line">&#125;);</span><br><span class="line">DataProviderCompiler converter = <span class="keyword">new</span> DataProviderCompiler();</span><br><span class="line">String drl = converter.compile(data, templateStream);</span><br></pre></td></tr></table></figure>

<h3 id="1-4-编译规则"><a href="#1-4-编译规则" class="headerlink" title="1.4 编译规则"></a>1.4 编译规则</h3><p>在模板渲染、编译成规则文件后，就可以正常的编译DRL规则文件， 新建会话等。<br> KieHelper 是 Drools提供的工具类, 可用于编译DRL规则文件， 新建会话等。<br>ps: 也可以使用其他的方式编译，这里只是为了简单</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">KieHelper helper = <span class="keyword">new</span> KieHelper();</span><br><span class="line">helper.addContent(drl, ResourceType.DRL);</span><br><span class="line">KieSession kieSession = helper.build().newKieSession();</span><br><span class="line">kieSession.insert(<span class="keyword">new</span> String(<span class="string">&quot;Hello, World!&quot;</span>));</span><br><span class="line">kieSession.fireAllRules();</span><br><span class="line">kieSession.dispose();</span><br></pre></td></tr></table></figure>

<h3 id="1-5-模板编译示例"><a href="#1-5-模板编译示例" class="headerlink" title="1.5 模板编译示例"></a>1.5 模板编译示例</h3><h4 id="1-5-1-DRT模板文件-template-drt"><a href="#1-5-1-DRT模板文件-template-drt" class="headerlink" title="1.5.1 DRT模板文件 template.drt"></a>1.5.1 DRT模板文件 template.drt</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">template header</span><br><span class="line">condition</span><br><span class="line">execution</span><br><span class="line"></span><br><span class="line"><span class="keyword">package</span> template</span><br><span class="line"></span><br><span class="line">template <span class="string">&quot;this is a test&quot;</span></span><br><span class="line"></span><br><span class="line">    rule <span class="string">&quot;test_@&#123;row.rowNumber&#125;&quot;</span></span><br><span class="line">        when</span><br><span class="line">            @&#123;condition&#125;</span><br><span class="line">        then</span><br><span class="line">            System.out.println(@&#123;execution&#125;);</span><br><span class="line">    end</span><br><span class="line"></span><br><span class="line">end template</span><br></pre></td></tr></table></figure>

<h4 id="1-5-2-单元测试"><a href="#1-5-2-单元测试" class="headerlink" title="1.5.2 单元测试"></a>1.5.2 单元测试</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Demo</span> </span>&#123;</span><br><span class="line">    <span class="keyword">static</span> KnowledgeBuilder builder;</span><br><span class="line">KieBase kieBase;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@BeforeClass</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">beforeClass</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        builder = KnowledgeBuilderFactory.newKnowledgeBuilder();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Before</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setUp</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * 1. 从本地模板DRT文件得到输入流</span></span><br><span class="line"><span class="comment">         * 2. 创建一个 ArrayDataProvider , 二维数组中元素按顺序与DRT文件中定义的变量一一对应</span></span><br><span class="line"><span class="comment">         * 3. 创建一个 DataProviderCompiler 对象用compile()方法渲染, 将二维数组中的元素一一填充到DRT模板中, 得到DRL(规则)字符串</span></span><br><span class="line"><span class="comment">         * 4. 加载DRL(规则)字符串</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        String pathToDrt = <span class="string">&quot;E:\\template.drt&quot;</span>;</span><br><span class="line">        <span class="keyword">try</span> (InputStream stream = <span class="keyword">new</span> FileInputStream(pathToDrt)) &#123;</span><br><span class="line">            DataProvider dataProvider = <span class="keyword">new</span> ArrayDataProvider(<span class="keyword">new</span> String[][]&#123;</span><br><span class="line">                    <span class="keyword">new</span> String[]&#123;<span class="string">&quot;String(this == \&quot;规则条件\&quot;)&quot;</span>, <span class="string">&quot;\&quot;规则动作\&quot;&quot;</span>&#125;</span><br><span class="line">            &#125;);</span><br><span class="line">            DataProviderCompiler compiler = <span class="keyword">new</span> DataProviderCompiler();</span><br><span class="line">            String DRL = compiler.compile(dataProvider, stream);</span><br><span class="line">            System.out.println(<span class="string">&quot;-----模板DRT渲染后的DRL-----&quot;</span>);</span><br><span class="line">            System.out.println(DRL);</span><br><span class="line">            System.out.println(<span class="string">&quot;-----模板DRT渲染后的DRL-----&quot;</span>);</span><br><span class="line">            <span class="keyword">byte</span>[] drlBytes = DRL.getBytes(<span class="string">&quot;UTF-8&quot;</span>);</span><br><span class="line">            Resource resourceTemplate = ResourceFactory.newByteArrayResource(drlBytes);</span><br><span class="line">            builder.add(resourceTemplate, ResourceType.DRL);</span><br><span class="line">        &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">        builder.add(resourceNative, ResourceType.DRL);</span><br><span class="line"><span class="comment">//        builder.add(resourceRemote, ResourceType.DRL);</span></span><br><span class="line">        kieBase = builder.newKieBase();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testTemplate</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        KieSession kieSession = kieBase.newKieSession();</span><br><span class="line">        kieSession.insert(<span class="string">&quot;规则条件&quot;</span>);</span><br><span class="line">        kieSession.fireAllRules();</span><br><span class="line">        kieSession.dispose();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="1-5-3-输出"><a href="#1-5-3-输出" class="headerlink" title="1.5.3 输出"></a>1.5.3 输出</h4><blockquote>
</blockquote>
<pre><code>-----模板DRT渲染后的DRL-----
package template
rule &quot;test_0&quot;
    when
        String(this == &quot;规则条件&quot;)
    then
        System.out.println(&quot;规则动作&quot;);
end
-----模板DRT渲染后的DRL-----
规则动作
</code></pre>
<h2 id="2-本地加载与远程加载"><a href="#2-本地加载与远程加载" class="headerlink" title="2 本地加载与远程加载"></a>2 本地加载与远程加载</h2><h3 id="2-1-创建本地DRL文件"><a href="#2-1-创建本地DRL文件" class="headerlink" title="2.1 创建本地DRL文件"></a>2.1 创建本地DRL文件</h3><p>创建远程的DRL文件，地址为 E:\native.drl</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> rules.<span class="keyword">native</span>;</span><br><span class="line">dialect  <span class="string">&quot;mvel&quot;</span></span><br><span class="line"></span><br><span class="line">rule <span class="string">&quot;native&quot;</span></span><br><span class="line">    when</span><br><span class="line">    then</span><br><span class="line">        System.out.println(<span class="string">&quot;本地加载成功&quot;</span>);</span><br><span class="line">end</span><br></pre></td></tr></table></figure>

<h3 id="2-2-创建远程DRL文件"><a href="#2-2-创建远程DRL文件" class="headerlink" title="2.2 创建远程DRL文件"></a>2.2 创建远程DRL文件</h3><p>创建远程的DRL文件，地址为 <a target="_blank" rel="noopener" href="http://localhost:8761/remote.drl">http://localhost:8761/remote.drl</a></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> rules.remote;</span><br><span class="line">dialect  <span class="string">&quot;mvel&quot;</span></span><br><span class="line"></span><br><span class="line">rule <span class="string">&quot;remote&quot;</span></span><br><span class="line">    when</span><br><span class="line">    then</span><br><span class="line">        System.out.println(<span class="string">&quot;远程加载成功&quot;</span>);</span><br><span class="line">end</span><br></pre></td></tr></table></figure>

<h3 id="2-3-单元测试"><a href="#2-3-单元测试" class="headerlink" title="2.3 单元测试"></a>2.3 单元测试</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Demo</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">static</span> KnowledgeBuilder builder;</span><br><span class="line">    KieBase kieBase;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@BeforeClass</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">beforeClass</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        builder = KnowledgeBuilderFactory.newKnowledgeBuilder();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Before</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setUp</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * 本地加载DRL</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        Resource resourceNative = ResourceFactory.newFileResource(<span class="string">&quot;E:\\native.drl&quot;</span>);</span><br><span class="line">        <span class="comment">/**</span></span><br><span class="line"><span class="comment">         * 远程加载URL</span></span><br><span class="line"><span class="comment">         */</span></span><br><span class="line">        String url = <span class="string">&quot;http://localhost:8761/remote.drl&quot;</span>;</span><br><span class="line">Resource resourceRemote = ResourceFactory.newUrlResource(url );</span><br><span class="line"><span class="comment">// 加载方式的不同</span></span><br><span class="line">builder.add(resourceNative, ResourceType.DRL);</span><br><span class="line">builder.add(resourceRemote, ResourceType.DRL);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Test</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testNativeAndRemote</span><span class="params">()</span> </span>&#123;</span><br><span class="line">        KieSession kieSession = kieBase.newKieSession();</span><br><span class="line">        kieSession.fireAllRules();</span><br><span class="line">        kieSession.dispose();</span><br><span class="line">    &#125;&#125;</span><br></pre></td></tr></table></figure>

<h3 id="2-4-输出"><a href="#2-4-输出" class="headerlink" title="2.4 输出"></a>2.4 输出</h3><blockquote>
<p>远程加载成功<br>本地加载成功</p>
</blockquote>
<h2 id="3-总结"><a href="#3-总结" class="headerlink" title="3 总结"></a>3 总结</h2><p>关键API：<br>Resource: 资源类，规则文件的加载<br>KnowledgeBuilder: 收集编译已经编写好的规则文件(drl)</p>
<p>从整体的收集、编译、执行上看，远程加载与本地加载大同小异，无非就是在使用Resource时加载规则文件上的不同。使用模板则在此基础上，需要将模板(drt)编译成规则(drl)。</p>

      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




    


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="">
    <link itemprop="mainEntityOfPage" href="http://littlefxc.github.io/2018/11/28/hello-world/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="一年春又来">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一年春又来">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          <a href="/blog/2018/11/28/hello-world/" class="post-title-link" itemprop="url">文章标题</a>
        </h2>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2018-11-28 00:00:00" itemprop="dateCreated datePublished" datetime="2018-11-28T00:00:00+08:00">2018-11-28</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-03-25 21:15:49" itemprop="dateModified" datetime="2021-03-25T21:15:49+08:00">2021-03-25</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/blog/categories/%E6%96%87%E7%AB%A0%E5%88%86%E7%B1%BB/" itemprop="url" rel="index"><span itemprop="name">文章分类</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
          <p>文章摘要写在前面，支持markdown左右语法。</p>
          <!--noindex-->
            <div class="post-button">
              <a class="btn" href="/blog/2018/11/28/hello-world/#more" rel="contents">
                阅读全文 &raquo;
              </a>
            </div>
          <!--/noindex-->
        
      
    </div>

    
    
    

    <footer class="post-footer">
        <div class="post-eof"></div>
      
    </footer>
  </article>
</div>




  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/blog/page/18/"><i class="fa fa-angle-left" aria-label="上一页"></i></a><a class="page-number" href="/blog/">1</a><span class="space">&hellip;</span><a class="page-number" href="/blog/page/18/">18</a><span class="page-number current">19</span>
  </nav>


<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">一年春又来</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/mist/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
<script src="/blog/js/utils.js"></script><script src="/blog/js/motion.js"></script><script src="/blog/js/schemes/muse.js"></script><script src="/blog/js/next-boot.js"></script>

  
<script src="/blog/js/local-search.js"></script>






  





</body>
</html>
